using UnityEngine;
using System.Collections.Generic;

public class GoodsManager : MonoBehaviour
{
    public static GoodsManager Instance { get; private set; }
    private Goods currentSelectedGoods;
    public List<Goods> allGoods = new List<Goods>();

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }

    public void SelectGoods(Goods goods)
    {
        if (currentSelectedGoods != null && currentSelectedGoods != goods)
        {
            currentSelectedGoods.Deselect();
        }

        currentSelectedGoods = goods;
    }

    //重置选中的物品
    public void ResetSelectedGoods()
    {
        currentSelectedGoods = null;
    }

    //获取选中的物品
    public Goods GetSelectedGoods()
    {
        return currentSelectedGoods;
    }

    public List<Goods> GetAllGoods()
    {
        return new List<Goods>(allGoods);
    }

    public void RegisterGoods(Goods goods)
    {
        if (!allGoods.Contains(goods))
        {
            allGoods.Add(goods);
            Debug.Log("注册物品" + allGoods.Count);
        }
    }

    public void UnregisterGoods(Goods goods)
    {
        allGoods.Remove(goods);
    }

    //清空所有物品
    public void ClearAllGoods()
    {
        allGoods.Clear();
    }

    
}